package com.bbznb.controller;

import com.bbznb.common.Result;
import com.bbznb.service.UserService;
import com.bbznb.util.PageData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/movies")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/tickets")
    public Result getTickets(@RequestParam("page")  Integer page, @RequestParam("size")  Integer size) {
         PageData pageData = userService.getTickets(page, size);
        return Result.build(200, "success", pageData);
    }
    @GetMapping("/ranking")
    public Result getRanking() {
        return Result.build(200, "success", userService.getRanking());
    }
    @PostMapping("tickets/{id}/buy")
    public Result buyTickets(@PathVariable Integer id) {
         userService.buyTickets(id);
        return Result.build(200, "success", null);
    }

}
